package pl.edu.pw.perg.compinfodb.ui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

@SuppressWarnings("serial")
public class ColorRenderer extends DefaultTableCellRenderer implements
    TableCellRenderer {

  public ColorRenderer() {
    // setOpaque(true); // MUST do this for background to show up.
  }

  @SuppressWarnings("unchecked")
  public Component getTableCellRendererComponent(JTable table, Object obj,
      boolean isSelected, boolean hasFocus, int row, int column) {
    Component cell = super.getTableCellRendererComponent(table, obj,
        isSelected, hasFocus, row, column);

    Color filterColor = new Color(170, 202, 215);
    Color newColor = new Color(215, 205, 170);
    // Color filterColor = new Color(0x5C, 0xC5, 0xC4);
    // Color newColor = new Color(0x5E, 0xC5, 0x5C);
    if (row == 0 && !isSelected) {
//      cell.setBackground(filterColor);
    }
    
    if(table.getModel().isCellEditable(row, column))
    	cell.setBackground(filterColor);
    // else if(!((FilterableTableModel<ITableData>) table.getModel()).
    // isRowPersistent(row))
    // cell.setBackground(newColor);
    else if (!isSelected)
      cell.setBackground(new Color(255, 255, 255));

    return cell;
  }
}
